package com.zzh.phone.hviews;


import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.zzh.lib.views.adapter.HBaseViewPagerAdapter;
import com.zzh.lib.views.transform.OverlapPageTransformer;
import com.zzh.lib.views.transform.OverlayTransformer;
import com.zzh.mvvm.base.BaseRabbitActivity;
import com.zzh.phone.hviews.databinding.ActOverlapSideBinding;
import com.zzh.phone.hviews.databinding.ItemImgOverlapBinding;
import com.zzh.phone.hviews.vm.OverlapSideViewModel;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.viewpager2.widget.ViewPager2;

/**
 * Created by ZZH on 2022/7/30.
 *
 * @Date: 2022/7/30
 * @Email: zzh_hz@126.com
 * @QQ: 1299234582
 * @Author: zzh
 * @Description:
 */
public class OverlapSideAct extends BaseRabbitActivity<OverlapSideViewModel, ActOverlapSideBinding> {
    @Override
    protected void initViewAndData(Bundle savedInstanceState) {

        BaseQuickAdapter<String, BaseViewHolder> adapter = new BaseQuickAdapter<>(R.layout.item_img) {
            @Override
            protected void convert(@NonNull BaseViewHolder holder, String url) {

                ImageView aiv_img = holder.getView(R.id.aiv_img);
                Glide.with(OverlapSideAct.this).load(url).into(aiv_img);
            }
        };

        List<String> list = new ArrayList<>();
        list.add("https://t7.baidu.com/it/u=4264092703,2967343056&fm=193&f=GIF");
        list.add("https://t7.baidu.com/it/u=3117604922,3746073075&fm=193&f=GIF");
        list.add("https://t7.baidu.com/it/u=2274349089,347993238&fm=193&f=GIF");
        list.add("https://t7.baidu.com/it/u=2326834340,3581527322&fm=193&f=GIF");
        list.add("https://t7.baidu.com/it/u=521842085,1119399820&fm=193&f=GIF");
        list.add("https://t7.baidu.com/it/u=2049395612,561497221&fm=193&f=GIF");
        list.add("https://t7.baidu.com/it/u=759065519,2943263676&fm=193&f=GIF");
        adapter.addData(list);

        bind.viewPager2.setAdapter(adapter);
        bind.viewPager2.setOrientation(ViewPager2.ORIENTATION_HORIZONTAL);
        bind.viewPager2.setPageTransformer(new OverlapPageTransformer(ViewPager2.ORIENTATION_HORIZONTAL, 0.8f, 0.8f, 0.8f, 0.8f));

        HBaseViewPagerAdapter<String> pagerAdapter = new HBaseViewPagerAdapter<>(this) {
            @NonNull
            @Override
            protected View getItemView(@NonNull Context ctx, String data, int position) {
                ItemImgOverlapBinding binding = ItemImgOverlapBinding.inflate(LayoutInflater.from(ctx));
                Glide.with(OverlapSideAct.this).load(data).into(binding.aivImg);
                return binding.getRoot();
            }
        };
        list = new ArrayList<>();
        list.add("https://t7.baidu.com/it/u=4264092703,2967343056&fm=193&f=GIF");
        list.add("https://t7.baidu.com/it/u=3117604922,3746073075&fm=193&f=GIF");
        list.add("https://t7.baidu.com/it/u=2274349089,347993238&fm=193&f=GIF");
        list.add("https://t7.baidu.com/it/u=2326834340,3581527322&fm=193&f=GIF");
        list.add("https://t7.baidu.com/it/u=521842085,1119399820&fm=193&f=GIF");
        list.add("https://t7.baidu.com/it/u=2049395612,561497221&fm=193&f=GIF");
        list.add("https://t7.baidu.com/it/u=759065519,2943263676&fm=193&f=GIF");
        pagerAdapter.addData(list);
        bind.viewPager.setAdapter(pagerAdapter);
        bind.viewPager.setPageTransformer(true, new OverlayTransformer(4, 40f, 40f));
        bind.viewPager.setOffscreenPageLimit(4);
    }

    @Override
    protected int initVariableId() {
        return BR.viewModel;
    }
}
